package com.nuc.kl.module.basedata.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nuc.kl.base.DaoSupportImpl;
import com.nuc.kl.module.basedata.entity.Navigation;
import com.nuc.kl.module.basedata.service.NavigationSerivce;

@Service
@Transactional
@SuppressWarnings("unchecked")
public class NavigationServiceImpl extends DaoSupportImpl<Navigation> implements NavigationSerivce{

	public List<Navigation> findBySQL(int start, int number, String findName) {
		return getSession().createQuery(//
				"FROM Navigation WHERE name LIKE '%" + findName + "%'")//
				.setFirstResult(start)//
				.setMaxResults(number)//
				.list();
	}

	public List<Navigation> findList(Long parentId) {
		
		if(parentId == null){
			return getSession().createQuery(//
			"FROM Navigation n WHERE n.parent.id IS null")//
			.list();
		}else{
			return listChildren(parentId);
		}
		
	}

	public List<Navigation> listChildren(Long parentId) {
		return getSession().createQuery(//
		"FROM Navigation n WHERE n.parent.id = ?")//
		.setParameter(0, parentId)//
		.list();
	}
	
}
